package com.briup.jdk8;

import java.util.ArrayList;
import java.util.stream.Stream;

/**
 * Stream 的中间操作
 */
public class StringMiddleOP {
    public static void main(String[] args) {
        Stream<String> stream = Stream.of("海鹏", "海螺", "海星", "海燕", "海绵宝宝", "海王", "海苔", "海白菜", "海公牛");
        //过滤
        Integer integer = stream.filter(i -> {
            char[] array = i.toCharArray();
            int sum = 0;
            for (char c : array) {
                sum += c;
            }
            return sum > 65535;
        })
                //映射  将元素变成其他类型的元素
                .map(String::length)
                //最终操作   计算
                .reduce((v1, v2) -> v1 + v2)
                .get();
        System.out.println(integer);
//                .forEach(System.out::println);



        Stream<Integer> is = Stream.of(1, 3, 7, 65, 15, 25, 63, 66, 38);

                is.limit(5)
                .skip(2)
                .forEach(System.out::println);

        Stream<String> ss = Stream.of("海鹏", "海螺", "海星", "海燕", "海绵宝宝", "海王", "海苔", "海白菜", "海公牛");
        long count = ss.map(String::length)
                .distinct()
                .count();
        System.out.println(count);


    }
}
